package com.rocsun.base;

import lombok.Getter;

/**
 * @program: rocsun-scali
 * @description:
 * @author: yx.guo
 * @create: 2025-10-19 16:25
 **/
@Getter
public enum RocsunErrorCodeEnum {

    // ======================== 基础通用 ========================
    SUCCESS(0, "操作成功"),
    FAIL(1, "操作失败"),
    PARAM_ERROR(1001, "参数错误"),
    UNAUTHORIZED(1002, "未授权"),
    FORBIDDEN(1003, "没有权限"),
    NOT_FOUND(1004, "资源不存在"),
    SERVER_ERROR(1005, "服务器内部错误"),

    // ======================== 用户相关 ========================
    USER_NOT_EXIST(2001, "用户不存在"),
    USER_ALREADY_EXIST(2002, "用户已存在"),
    PASSWORD_ERROR(2003, "密码错误"),
    TOKEN_EXPIRED(2004, "登录状态已过期"),

    // ======================== 业务相关 ========================
    DATA_NOT_FOUND(3001, "数据未找到"),
    DUPLICATE_OPERATION(3002, "重复操作"),
    OPERATION_NOT_ALLOWED(3003, "不允许的操作");

    // ======================== 字段与构造 ========================
    private final Integer code;
    private final String message;

    RocsunErrorCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Enum getByCode(Integer code) {
        for (RocsunErrorCodeEnum e : values()) {
            if (e.code.intValue() == code) {
                return e;
            }
        }
        return null;
    }

}
